// 输入数组和规则 返回对应的列表
const getRegList = (list, reg) => list.map((item) => item.match(reg));

const demoList = ["abc", "aabc", "abab", ""];
const reg1 = /a+/gi;
const resultDemoList = getRegList(demoList, reg1);
console.log({ resultDemoList });

// * 号 匹配 0次或者多次字符
let soccerWord = "gooooooooal!";
let gPhrase = "gut feeling";
let oPhrase = "over the moon";
const demoList2 = [soccerWord, gPhrase, oPhrase];
let goRegex = /go*/;
console.log(getRegList(demoList2, goRegex));

// ? 表示非贪婪模式 返回最小的单元 默认都是贪婪模式
const str1 = "titanic";
const tanLan = /t[a-z]*i/;
const feiTanLan = /t[a-z]*?i/;

console.log("贪婪", getRegList([str1], tanLan));
console.log("非贪婪", getRegList([str1], feiTanLan));

// let text = "<h1>Winter is coming</h1>";
// let myRegex = /<.*?>/; // Change this line
// let result = text.match(myRegex);

// ^ 不仅可以表示取反 还能表示限制开头
const str2 = "Cal and Ricky both like racing";
const kaiTouReg = /^Cal/;
console.log(kaiTouReg.test(str2));
console.log(getRegList([str2], kaiTouReg));

// $ 表示以什么结尾
const caboose = "The last car on a train is the caboose";
const lastRegex = /caboose$/; // Change this line
const result = lastRegex.test(caboose);
console.log({ result });

// 用户名测试
const username = "JACK";
const userCheck = /^\D[a-z]+?\d*$/gi; // Change this line
const result2 = userCheck.test(username);
console.log(result2);
